package com.csdware.devilsalarm;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.WindowInsets;
import android.view.WindowInsetsController;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;

public class Activity_Settings extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        if (android.os.Build.VERSION.SDK_INT >= 30) {
            WindowInsetsController windowInsetsController = getWindow().getInsetsController();
            if (windowInsetsController != null) {
                windowInsetsController.hide(WindowInsets.Type.statusBars() | WindowInsets.Type.navigationBars());
                windowInsetsController.setSystemBarsBehavior(WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
            }
        }
        setContentView(R.layout.activity_settings);

        TextView ButtonKillApp = findViewById(R.id.bt_kill_app);
        ButtonKillApp.setOnClickListener(view -> {
            finishAffinity();
            System.exit(0);
        });

        SharedPreferences SharedPrefs = getSharedPreferences("data", MODE_PRIVATE);
        SharedPreferences.Editor SharedPrefsEditor = SharedPrefs.edit();
        RadioButton RadioButtonAmapLocationService = findViewById(R.id.rb_amap_location_service);
        RadioButton RadioButtonAndroidDefaultLocationService = findViewById(R.id.rb_android_default_location_service);
        RadioButtonAmapLocationService.setOnClickListener(view -> {
            SharedPrefsEditor.putInt("LocationChoice", 0);
            SharedPrefsEditor.apply();
            Toast.makeText(getApplicationContext(), getString(R.string.restart_app_to_apply_changes), Toast.LENGTH_SHORT).show();
        });
        RadioButtonAndroidDefaultLocationService.setOnClickListener(view -> {
            SharedPrefsEditor.putInt("LocationChoice", 1);
            SharedPrefsEditor.apply();
            Toast.makeText(getApplicationContext(), getString(R.string.restart_app_to_apply_changes), Toast.LENGTH_SHORT).show();
        });
        int ChosenOption = SharedPrefs.getInt("LocationChoice", 0);
        switch (ChosenOption){
            case 0:
                RadioButtonAmapLocationService.setChecked(true);
                break;
            case 1:
                RadioButtonAndroidDefaultLocationService.setChecked(true);
                break;
        }
    }
}
